package com;

import com.aracoix.model._MappingKit;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;

public class GeneratorConfig extends JFinalConfig{

    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 80, "/", 5);
    }

    @Override
    public void configConstant(Constants me) {
        // 加载少量必要配置，随后可用PropKit.get(...)获取值
        PropKit.use("a_little_config.txt");
        me.setDevMode(PropKit.getBoolean("devMode", false));

    }

    @Override
    public void configEngine(Engine me) {

    }

    @Override
    public void configHandler(Handlers arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void configInterceptor(Interceptors arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void configPlugin(Plugins me) {
        // 配置 druid 数据库连接池插件
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("main.url"), PropKit.get("main.user"), PropKit.get("main.pwd").trim());
        me.add(druidPlugin);

        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        // 所有映射在 MappingKit 中自动化搞定
        _MappingKit.mapping(arp);
        me.add(arp);

    }

    @Override
    public void configRoute(Routes arg0) {
        // TODO Auto-generated method stub

    }

    public static DruidPlugin createDruidPlugin() {
        return new DruidPlugin(PropKit.get("main.url"), PropKit.get("main.user"), PropKit.get("main.pwd").trim());
    }

}
